﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PassportsModel;
using Shared.Utilities;

namespace RulesInterface
{
    public static class BlazeRulesInterface
    {
        private static passportappServiceSoapClient _passportappServiceSoapClient;

        public static passportappServiceSoapClient PassportappServiceSoapClient
        {
            get {
                passportappServiceSoapClient _passportappServiceSoapClient = new passportappServiceSoapClient();
                return _passportappServiceSoapClient; 
            }        
        }

        public static PassportResponse EvaluatePassportRequest(PassportRequest passportRequest)
        {
            bool status = false;

            string passportRequestXml = Serialization.Serialize<PassportRequest>(passportRequest);

            // Alernateive method
            //CustomClientChannel<passportappServiceSoapChannel> channel = new CustomClientChannel<passportappServiceSoapChannel>("passportappServiceSoap", "RulesInterface.config");
            CustomClientChannel<passportappServiceSoapChannel> channel = new CustomClientChannel<passportappServiceSoapChannel>("test", "RulesInterface.config");
            passportappServiceSoapChannel client = channel.CreateChannel();

            entryPointPassportApplicationRequest entryPointPassportApplicationRequest = new entryPointPassportApplicationRequest(
                                    new entryPointPassportApplicationRequestBody(passportRequestXml));


            entryPointPassportApplicationResponse rulesResponse = client.entryPointPassportApplication(entryPointPassportApplicationRequest);

            //// Create a client
            ////CalculatorClient client = new CalculatorClient();

            //// Call the Add service operation.
            //double value1 = 100.00D;
            //double value2 = 15.99D;
            //double result = client.Add(value1, value2);

            //string xmlRulesResponse = PassportappServiceSoapClient.entryPointPassportApplication(passportRequestXml);

            PassportResponse passportResponse = Serialization.Deserialize<PassportResponse>(rulesResponse.Body.entryPointPassportApplicationResult);

            if (passportResponse.Status == eStatus.Success)
            {
                status = true;
            }

           
            return (passportResponse);
        }
    }
}
